# example.py - Example usage of DeeIRC IRC Framework.
# Copyright (C) 2010 Daniel Callander
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License

import DeeIRC.IRC
import DeeIRC.Events

class ExampleMessageEvent(DeeIRC.Events.MessageEvent):
	def fire(self, irc, nick, target, message):
		"""Causes the bot to respond back when you say hello."""
		if message.upper().find("HELLO") >= 0 and message.upper().find(irc.nick.upper()) >= 0:
			irc.sendMessage(target, "Hello, " + nick)

class ExampleConnectedEvent(DeeIRC.Events.ConnectedEvent):
	def fire(self, irc):
		"""Joins the main channel upon connect."""
		irc.sendJoin(irc.main_channel)		
		
class ExampleBot(DeeIRC.IRC.DeeIRC):
	"""Example bot. Responds to people saying hello and will rejoin a channel
	upon being kicked."""
	
	def __init__(self, channel):
		"""Constructor. Adds events to the framework."""
		super(ExampleBot, self).__init__("ExampleBot")
		
		self.main_channel = channel
		self.main_server = server
		
		# Add our custom events
		self.addEvent("connected", ExampleConnectedEvent())
		self.addEvent("message", ExampleMessageEvent())

# ----------------------------------------------------------------------------

if __name__ == "__main__":
	server = "irc.synirc.org"
	channel = "#glasnost"
	
	bot = ExampleBot(channel)
	bot.connect(server)